package com.habdqn.easybuy.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @author Xing.Jiejian
 * @date 2020/11/27 0027
 */
@WebFilter(filterName = "BaseFilter", urlPatterns = "/*")
public class BaseFilter implements Filter {
    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {
        // 排除静态资源目录
        String staticLocation = "/static/";
        if (!((HttpServletRequest) req).getServletPath().startsWith(staticLocation)) {
            // 字符编码设定
            req.setCharacterEncoding("utf-8");
            resp.setCharacterEncoding("utf-8");
        }
        chain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig config) throws ServletException {
    }

}
